package com.heima.wemedia.config;

import com.heima.common.message.PublishArticleConstants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 声明定时发布文章
 * 所需的 所有交换机  队列 及 绑定关系
 **/

@Configuration
public class DeclarePubArticleRabbitConfig {
    @Bean
    DirectExchange delayExchange(){
        return ExchangeBuilder.directExchange(PublishArticleConstants.DELAY_DIRECT_EXCHANGE)
                .delayed()  //设置为远程交换机类型
                .build();
    }

    @Bean
    Queue delayQueue(){
        return new Queue(PublishArticleConstants.PUBLISH_ARTICLE_QUEUE);
    }

    @Bean
    Binding binding(){
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with(PublishArticleConstants.PUBLISH_ARTICLE_ROUTE_KEY);
    }

}
